Unable to wait for async call in Javascript